// 删除经期周期信息云函数
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()

exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const userId = wxContext.OPENID
  
  try {
    const { year, month } = event
    
    console.log('删除经期周期信息:', {
      userId,
      year,
      month
    })

    // 删除指定月份的经期周期
    const result = await db.collection('period_cycles')
      .where({
        user_id: userId,
        year: year,
        month: month
      })
      .remove()

    console.log('删除经期周期结果:', result)
    
    return {
      status: 'success',
      message: '经期周期删除成功',
      data: {
        removed: result.stats.removed
      }
    }

  } catch (error) {
    console.error('删除经期周期失败:', error)
    return {
      status: 'error',
      message: '删除经期周期失败',
      error: error.message
    }
  }
}
